package com.hnkywl.sts.service.tjbb;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.tjbb.YdcbdbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: SDE09
 * Date: 13-10-18
 * Time: 上午11:13
 * To change this template use File | Settings | File Templates.
 */
@Service
public class YdcbdbService {
    private YdcbdbDao ydcbdbDao;

    /**
     * 移动成本对比表
      * @param gsid
     * @param begindt
     * @param enddt
     * @param jylb
     * @param xslx
     * @param custname
     * @param pageNo
     * @param pageSize
     * @return
     */
    public String ydcbdbList(Integer gsid,  Date begindt, Date enddt,Integer jylb,Integer xslx, String custname,
                            Integer pageNo, Integer pageSize) {
        Map<String, Object> result = ydcbdbDao.ydcbdbList(gsid, begindt, enddt, jylb,  xslx,custname,pageNo, pageSize);
        Integer total=(Integer)result.get("total");
        List<Map> rows = (List<Map>)result.get("rows");
        List<Map> footer = (List<Map>)result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson +",\"total\":"+total+ "}";
        return json;
    }

    /**
     * 移动成本对比表导出
     * @param gsid
     * @param begindt
     * @param enddt
     * @param jylb
     * @param xslx
     * @param custname
     * @return
     */
    public Map ydcbdbListExport(Integer gsid,   Date begindt, Date enddt,Integer jylb,Integer xslx, String custname){
        Map<String, Object> result = ydcbdbDao.ydcbdbList(gsid, begindt, enddt, jylb,  xslx,custname, 1,100000);
        return result;
    }



    @Autowired
    public void setYdcbdbDao(YdcbdbDao ydcbdbDao) {
        this.ydcbdbDao = ydcbdbDao;
    }
}
